package com.example.redisstudy;

import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * @Classname StringContainsTest
 * @Description TODO
 * @Version 1.0.0
 * @Date 2024/6/12 16:26
 * @Created by ligang
 */
public class StringContainsTest {
    public static void main(String[] args) {
        // 示例数据
        List<String> data = Arrays.asList(
                "和哈哈哈哈斤斤计较",
                "和哈哈哈哈斤斤计较",
                "和哈哈哈哈斤斤计较",
                "和哈哈哈哈斤斤计较"
        );

        // 关键字列表
        List<String> keywords = Arrays.asList("关键字1", "关键字2", "关键字3", "关键字4", "关键字5");

        // 构建正则表达式模式
        String patternString = keywords.stream()
                .map(Pattern::quote)
                .collect(Collectors.joining("|"));
        Pattern pattern = Pattern.compile(patternString);

        // 并行处理数据并筛选包含所有关键字的字符串
        List<String> result = data.parallelStream()
                .filter(s -> containsAllKeywords(s, keywords))
                .collect(Collectors.toList());

        // 输出结果
        result.forEach(System.out::println);
    }

    // 检查字符串是否包含所有关键字
    private static boolean containsAllKeywords(String str, List<String> keywords) {
        for (String keyword : keywords) {
            if (!str.contains(keyword)) {
                return false;
            }
        }
        return true;
    }
}
